﻿
namespace NetROS.Tiers.Windows.Forms
{
	/// <summary>
	/// abstract DokumentStavkaProknjizenNaKonto typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class DokumentStavkaProknjizenNaKontoDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<DokumentStavkaProknjizenNaKontoDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.DokumentStavkaProknjizenNaKonto _currentDokumentStavkaProknjizenNaKonto = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxDokumentStavkaProknjizenNaKontoDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxDokumentStavkaProknjizenNaKontoErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxDokumentStavkaProknjizenNaKontoBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the Konto property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxKontoDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the IDDokumentStavka property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxIDDokumentStavkaDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
				
		private Entities.TList<Entities.DokumentStavka> _IDDokumentStavkaList;
		
		/// <summary> 
		/// The list of selectable DokumentStavka
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.DokumentStavka> IDDokumentStavkaList
		{
			get {return this._IDDokumentStavkaList;}
			set 
			{
				this._IDDokumentStavkaList = value;
				this.uxIDDokumentStavkaDataGridViewColumn.DataSource = null;
				this.uxIDDokumentStavkaDataGridViewColumn.DataSource = this._IDDokumentStavkaList;
			}
		}
		
		private bool _allowNewItemInIDDokumentStavkaList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of DokumentStavka
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInIDDokumentStavkaList
		{
			get { return _allowNewItemInIDDokumentStavkaList;}
			set
			{
				this._allowNewItemInIDDokumentStavkaList = value;
				this.uxIDDokumentStavkaDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.DokumentStavkaProknjizenNaKonto> _DokumentStavkaProknjizenNaKontoList;
				
		/// <summary> 
		/// The list of DokumentStavkaProknjizenNaKonto to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.DokumentStavkaProknjizenNaKonto> DokumentStavkaProknjizenNaKontoList
		{
			get {return this._DokumentStavkaProknjizenNaKontoList;}
			set
			{
				this._DokumentStavkaProknjizenNaKontoList = value;
				this.uxDokumentStavkaProknjizenNaKontoBindingSource.DataSource = null;
				this.uxDokumentStavkaProknjizenNaKontoBindingSource.DataSource = value;
				this.uxDokumentStavkaProknjizenNaKontoDataGridView.DataSource = null;
				this.uxDokumentStavkaProknjizenNaKontoDataGridView.DataSource = this.uxDokumentStavkaProknjizenNaKontoBindingSource;				
				//this.uxDokumentStavkaProknjizenNaKontoBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxDokumentStavkaProknjizenNaKontoBindingSource_ListChanged);
				this.uxDokumentStavkaProknjizenNaKontoBindingSource.CurrentItemChanged += new System.EventHandler(OnDokumentStavkaProknjizenNaKontoBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnDokumentStavkaProknjizenNaKontoBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentDokumentStavkaProknjizenNaKonto = uxDokumentStavkaProknjizenNaKontoBindingSource.Current as Entities.DokumentStavkaProknjizenNaKonto;
			
			if (_currentDokumentStavkaProknjizenNaKonto != null)
			{
				_currentDokumentStavkaProknjizenNaKonto.Validate();
			}
			//_DokumentStavkaProknjizenNaKonto.Validate();
			OnCurrentEntityChanged();
		}

		//void uxDokumentStavkaProknjizenNaKontoBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.DokumentStavkaProknjizenNaKonto"/> instance.
		/// </summary>
		public Entities.DokumentStavkaProknjizenNaKonto SelectedDokumentStavkaProknjizenNaKonto
		{
			get {return this._currentDokumentStavkaProknjizenNaKonto;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxDokumentStavkaProknjizenNaKontoDataGridView.VirtualMode;}
			set
			{
				this.uxDokumentStavkaProknjizenNaKontoDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxDokumentStavkaProknjizenNaKontoDataGridView.AllowUserToAddRows;}
			set {this.uxDokumentStavkaProknjizenNaKontoDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxDokumentStavkaProknjizenNaKontoDataGridView.AllowUserToDeleteRows;}
			set {this.uxDokumentStavkaProknjizenNaKontoDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxDokumentStavkaProknjizenNaKontoDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxDokumentStavkaProknjizenNaKontoDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="DokumentStavkaProknjizenNaKontoDataGridViewBase"/> class.
		/// </summary>
		public DokumentStavkaProknjizenNaKontoDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxDokumentStavkaProknjizenNaKontoDataGridView = new System.Windows.Forms.DataGridView();
			this.uxDokumentStavkaProknjizenNaKontoBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxDokumentStavkaProknjizenNaKontoErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxKontoDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxIDDokumentStavkaDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			//this.uxIDDokumentStavkaBindingSource = new DokumentStavkaBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDDokumentStavkaBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentStavkaProknjizenNaKontoDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentStavkaProknjizenNaKontoBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentStavkaProknjizenNaKontoErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxDokumentStavkaProknjizenNaKontoErrorProvider
			// 
			this.uxDokumentStavkaProknjizenNaKontoErrorProvider.ContainerControl = this;
			this.uxDokumentStavkaProknjizenNaKontoErrorProvider.DataSource = this.uxDokumentStavkaProknjizenNaKontoBindingSource;						
			// 
			// uxDokumentStavkaProknjizenNaKontoDataGridView
			// 
			this.uxDokumentStavkaProknjizenNaKontoDataGridView.AutoGenerateColumns = false;
			this.uxDokumentStavkaProknjizenNaKontoDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxDokumentStavkaProknjizenNaKontoDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxKontoDataGridViewColumn,
		this.uxIDDokumentStavkaDataGridViewColumn			});
			this.uxDokumentStavkaProknjizenNaKontoDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxDokumentStavkaProknjizenNaKontoDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxDokumentStavkaProknjizenNaKontoDataGridView.Name = "uxDokumentStavkaProknjizenNaKontoDataGridView";
			this.uxDokumentStavkaProknjizenNaKontoDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxDokumentStavkaProknjizenNaKontoDataGridView.TabIndex = 0;	
			this.uxDokumentStavkaProknjizenNaKontoDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxDokumentStavkaProknjizenNaKontoDataGridView.EnableHeadersVisualStyles = false;
			this.uxDokumentStavkaProknjizenNaKontoDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnDokumentStavkaProknjizenNaKontoDataGridViewDataError);
			this.uxDokumentStavkaProknjizenNaKontoDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnDokumentStavkaProknjizenNaKontoDataGridViewCellValueNeeded);
			this.uxDokumentStavkaProknjizenNaKontoDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnDokumentStavkaProknjizenNaKontoDataGridViewCellValuePushed);
			
			//
			// uxKontoDataGridViewColumn
			//
			this.uxKontoDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxKontoDataGridViewColumn.DataPropertyName = "Konto";
			this.uxKontoDataGridViewColumn.HeaderText = "Konto";
			this.uxKontoDataGridViewColumn.Name = "uxKontoDataGridViewColumn";
			this.uxKontoDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxKontoDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxKontoDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDDokumentStavkaDataGridViewColumn
			//
			this.uxIDDokumentStavkaDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDDokumentStavkaDataGridViewColumn.DataPropertyName = "IDDokumentStavka";
			this.uxIDDokumentStavkaDataGridViewColumn.HeaderText = "IDDokumentStavka";
			this.uxIDDokumentStavkaDataGridViewColumn.Name = "uxIDDokumentStavkaDataGridViewColumn";
			this.uxIDDokumentStavkaDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDDokumentStavkaDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDDokumentStavkaDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDDokumentStavkaDataGridViewColumn
			//				
			this.uxIDDokumentStavkaDataGridViewColumn.DisplayMember = "IDOrgJedOd";	
			this.uxIDDokumentStavkaDataGridViewColumn.ValueMember = "ID";	
			this.uxIDDokumentStavkaDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxIDDokumentStavkaDataGridViewColumn.DataSource = uxIDDokumentStavkaBindingSource;				
				
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxDokumentStavkaProknjizenNaKontoDataGridView);
			this.Name = "DokumentStavkaProknjizenNaKontoDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDDokumentStavkaBindingSource)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentStavkaProknjizenNaKontoErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentStavkaProknjizenNaKontoDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentStavkaProknjizenNaKontoBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				DokumentStavkaProknjizenNaKontoDataGridViewEventArgs args = new DokumentStavkaProknjizenNaKontoDataGridViewEventArgs();
				args.DokumentStavkaProknjizenNaKonto = _currentDokumentStavkaProknjizenNaKonto;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class DokumentStavkaProknjizenNaKontoDataGridViewEventArgs : System.EventArgs
		{
			private Entities.DokumentStavkaProknjizenNaKonto	_DokumentStavkaProknjizenNaKonto;
	
			/// <summary>
			/// the  Entities.DokumentStavkaProknjizenNaKonto instance.
			/// </summary>
			public Entities.DokumentStavkaProknjizenNaKonto DokumentStavkaProknjizenNaKonto
			{
				get { return _DokumentStavkaProknjizenNaKonto; }
				set { _DokumentStavkaProknjizenNaKonto = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxDokumentStavkaProknjizenNaKontoDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnDokumentStavkaProknjizenNaKontoDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxDokumentStavkaProknjizenNaKontoDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnDokumentStavkaProknjizenNaKontoDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxDokumentStavkaProknjizenNaKontoDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxKontoDataGridViewColumn":
						e.Value = DokumentStavkaProknjizenNaKontoList[e.RowIndex].Konto;
						break;
					case "uxIDDokumentStavkaDataGridViewColumn":
						e.Value = DokumentStavkaProknjizenNaKontoList[e.RowIndex].IDDokumentStavka;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxDokumentStavkaProknjizenNaKontoDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnDokumentStavkaProknjizenNaKontoDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxDokumentStavkaProknjizenNaKontoDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxKontoDataGridViewColumn":
						DokumentStavkaProknjizenNaKontoList[e.RowIndex].Konto = (System.String)e.Value;
						break;
					case "uxIDDokumentStavkaDataGridViewColumn":
						DokumentStavkaProknjizenNaKontoList[e.RowIndex].IDDokumentStavka = (System.Int32)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
